/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.cmu.cs.webapp.ioms.models.impl;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.ui.IActionFilter;

import edu.cmu.cs.webapp.ioms.dao.DataAccessException;
import edu.cmu.cs.webapp.ioms.dao.IngredientDAO;
import edu.cmu.cs.webapp.ioms.dao.impl.FormulaDAOImpl;
import edu.cmu.cs.webapp.ioms.dao.impl.IngredientDAOImpl;
import edu.cmu.cs.webapp.ioms.dao.impl.LineItemDAOImpl;
import edu.cmu.cs.webapp.ioms.dao.impl.OrderDAOImpl;
import edu.cmu.cs.webapp.ioms.dao.impl.ProductDAOImpl;
import edu.cmu.cs.webapp.ioms.models.Client;
import edu.cmu.cs.webapp.ioms.models.FormularRecord;
import edu.cmu.cs.webapp.ioms.models.IOMSPackage;
import edu.cmu.cs.webapp.ioms.models.Ingredient;
import edu.cmu.cs.webapp.ioms.models.LineItem;
import edu.cmu.cs.webapp.ioms.models.OrderStatus;
import edu.cmu.cs.webapp.ioms.models.Product;
import edu.cmu.cs.webapp.ioms.models.PurchaseOrder;

/**
 * <!-- begin-user-doc --> An implementation of the model object '
 * <em><b>Purchase Order</b></em>'. <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 * <li>{@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getOrder_id
 * <em>Order id</em>}</li>
 * <li>
 * {@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getOrder_date
 * <em>Order date</em>}</li>
 * <li>
 * {@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getShipping_address
 * <em>Shipping address</em>}</li>
 * <li>
 * {@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getShipping_city
 * <em>Shipping city</em>}</li>
 * <li>
 * {@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getShipping_state
 * <em>Shipping state</em>}</li>
 * <li>
 * {@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getShipping_country
 * <em>Shipping country</em>}</li>
 * <li>
 * {@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getExpected_shipping_date
 * <em>Expected shipping date</em>}</li>
 * <li>{@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getStatus
 * <em>Status</em>}</li>
 * <li>{@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getClient
 * <em>Client</em>}</li>
 * <li>{@link edu.cmu.cs.webapp.ioms.models.impl.PurchaseOrderImpl#getItems <em>
 * Items</em>}</li>
 * </ul>
 * </p>
 * 
 * @generated
 */
public class PurchaseOrderImpl extends EObjectImpl implements PurchaseOrder,
		IActionFilter {
	/**
	 * The default value of the '{@link #getOrder_id() <em>Order id</em>}'
	 * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getOrder_id()
	 * @generated
	 * @ordered
	 */
	protected static final int ORDER_ID_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getOrder_id() <em>Order id</em>}'
	 * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getOrder_id()
	 * @generated
	 * @ordered
	 */
	protected int order_id = ORDER_ID_EDEFAULT;

	/**
	 * The default value of the '{@link #getOrder_date() <em>Order date</em>}'
	 * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getOrder_date()
	 * @generated
	 * @ordered
	 */
	protected static final Date ORDER_DATE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getOrder_date() <em>Order date</em>}'
	 * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getOrder_date()
	 * @generated
	 * @ordered
	 */
	protected Date order_date = ORDER_DATE_EDEFAULT;

	/**
	 * The default value of the '{@link #getShipping_address()
	 * <em>Shipping address</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_address()
	 * @generated
	 * @ordered
	 */
	protected static final String SHIPPING_ADDRESS_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getShipping_address()
	 * <em>Shipping address</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_address()
	 * @generated
	 * @ordered
	 */
	protected String shipping_address = SHIPPING_ADDRESS_EDEFAULT;

	/**
	 * The default value of the '{@link #getShipping_city()
	 * <em>Shipping city</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_city()
	 * @generated
	 * @ordered
	 */
	protected static final String SHIPPING_CITY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getShipping_city()
	 * <em>Shipping city</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_city()
	 * @generated
	 * @ordered
	 */
	protected String shipping_city = SHIPPING_CITY_EDEFAULT;

	/**
	 * The default value of the '{@link #getShipping_state()
	 * <em>Shipping state</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_state()
	 * @generated
	 * @ordered
	 */
	protected static final String SHIPPING_STATE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getShipping_state()
	 * <em>Shipping state</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_state()
	 * @generated
	 * @ordered
	 */
	protected String shipping_state = SHIPPING_STATE_EDEFAULT;

	/**
	 * The default value of the '{@link #getShipping_country()
	 * <em>Shipping country</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_country()
	 * @generated
	 * @ordered
	 */
	protected static final String SHIPPING_COUNTRY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getShipping_country()
	 * <em>Shipping country</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getShipping_country()
	 * @generated
	 * @ordered
	 */
	protected String shipping_country = SHIPPING_COUNTRY_EDEFAULT;

	/**
	 * The default value of the '{@link #getExpected_shipping_date()
	 * <em>Expected shipping date</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getExpected_shipping_date()
	 * @generated
	 * @ordered
	 */
	protected static final Date EXPECTED_SHIPPING_DATE_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getExpected_shipping_date()
	 * <em>Expected shipping date</em>}' attribute. <!-- begin-user-doc --> <!--
	 * end-user-doc -->
	 * 
	 * @see #getExpected_shipping_date()
	 * @generated
	 * @ordered
	 */
	protected Date expected_shipping_date = EXPECTED_SHIPPING_DATE_EDEFAULT;

	/**
	 * The default value of the '{@link #getStatus() <em>Status</em>}'
	 * attribute. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getStatus()
	 * @generated
	 * @ordered
	 */
	protected static final OrderStatus STATUS_EDEFAULT = OrderStatus.PENDING;

	/**
	 * The cached value of the '{@link #getStatus() <em>Status</em>}' attribute.
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getStatus()
	 * @generated
	 * @ordered
	 */
	protected OrderStatus status = STATUS_EDEFAULT;

	/**
	 * The cached value of the '{@link #getClient() <em>Client</em>}' reference.
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getClient()
	 * @generated
	 * @ordered
	 */
	protected Client client;

	/**
	 * The cached value of the '{@link #getItems() <em>Items</em>}' reference
	 * list. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getItems()
	 * @generated
	 * @ordered
	 */
	protected EList<LineItem> items;

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	protected PurchaseOrderImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return IOMSPackage.Literals.PURCHASE_ORDER;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public int getOrder_id() {
		return order_id;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setOrder_id(int newOrder_id) {
		int oldOrder_id = order_id;
		order_id = newOrder_id;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__ORDER_ID, oldOrder_id, order_id));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public Date getOrder_date() {
		return order_date;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setOrder_date(Date newOrder_date) {
		Date oldOrder_date = order_date;
		order_date = newOrder_date;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__ORDER_DATE, oldOrder_date,
					order_date));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public String getShipping_address() {
		return shipping_address;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setShipping_address(String newShipping_address) {
		String oldShipping_address = shipping_address;
		shipping_address = newShipping_address;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__SHIPPING_ADDRESS,
					oldShipping_address, shipping_address));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public String getShipping_city() {
		return shipping_city;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setShipping_city(String newShipping_city) {
		String oldShipping_city = shipping_city;
		shipping_city = newShipping_city;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__SHIPPING_CITY,
					oldShipping_city, shipping_city));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public String getShipping_state() {
		return shipping_state;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setShipping_state(String newShipping_state) {
		String oldShipping_state = shipping_state;
		shipping_state = newShipping_state;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__SHIPPING_STATE,
					oldShipping_state, shipping_state));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public String getShipping_country() {
		return shipping_country;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setShipping_country(String newShipping_country) {
		String oldShipping_country = shipping_country;
		shipping_country = newShipping_country;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__SHIPPING_COUNTRY,
					oldShipping_country, shipping_country));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public Date getExpected_shipping_date() {
		return expected_shipping_date;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setExpected_shipping_date(Date newExpected_shipping_date) {
		Date oldExpected_shipping_date = expected_shipping_date;
		expected_shipping_date = newExpected_shipping_date;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__EXPECTED_SHIPPING_DATE,
					oldExpected_shipping_date, expected_shipping_date));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public OrderStatus getStatus() {
		return status;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setStatus(OrderStatus newStatus) {
		OrderStatus oldStatus = status;
		status = newStatus == null ? STATUS_EDEFAULT : newStatus;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__STATUS, oldStatus, status));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public Client getClient() {
		if (client != null && client.eIsProxy()) {
			InternalEObject oldClient = (InternalEObject) client;
			client = (Client) eResolveProxy(oldClient);
			if (client != oldClient) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE,
							IOMSPackage.PURCHASE_ORDER__CLIENT, oldClient,
							client));
			}
		}
		return client;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public Client basicGetClient() {
		return client;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void setClient(Client newClient) {
		Client oldClient = client;
		client = newClient;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					IOMSPackage.PURCHASE_ORDER__CLIENT, oldClient, client));
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public EList<LineItem> getItems() {
		if (items == null) {
			items = new EObjectResolvingEList<LineItem>(LineItem.class, this,
					IOMSPackage.PURCHASE_ORDER__ITEMS);
		}
		return items;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc --> Christian
	 * 
	 * @generated NOT
	 */
	public void setItems(EList<LineItem> items) {
		this.items = items;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public void accept() {
		this.getItems().clear();
		try {
			new LineItemDAOImpl().getOrderItems(this);

			for (LineItem item : getItems()) {
				Product p = item.getProduct();
				List<FormularRecord> forms = new FormulaDAOImpl()
						.getFormProd(p);
				for (FormularRecord f : forms) {

					IngredientDAO id = new IngredientDAOImpl();
					double q = f.getIng_std_quantity() * item.getQuantity();
					Ingredient ing = id.getIng(f.getIngredient());
					double new_inventory = ing.getInventory() - q;
					id.chargeInventory(ing.getIng_id(), new_inventory);
				}
			}

			// update the status to accepted
			setStatus(OrderStatus.ACCEPTED);
			new OrderDAOImpl().updateOrder(this);

		} catch (DataAccessException e) {
		}

	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case IOMSPackage.PURCHASE_ORDER__ORDER_ID:
			return getOrder_id();
		case IOMSPackage.PURCHASE_ORDER__ORDER_DATE:
			return getOrder_date();
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_ADDRESS:
			return getShipping_address();
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_CITY:
			return getShipping_city();
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_STATE:
			return getShipping_state();
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_COUNTRY:
			return getShipping_country();
		case IOMSPackage.PURCHASE_ORDER__EXPECTED_SHIPPING_DATE:
			return getExpected_shipping_date();
		case IOMSPackage.PURCHASE_ORDER__STATUS:
			return getStatus();
		case IOMSPackage.PURCHASE_ORDER__CLIENT:
			if (resolve)
				return getClient();
			return basicGetClient();
		case IOMSPackage.PURCHASE_ORDER__ITEMS:
			return getItems();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case IOMSPackage.PURCHASE_ORDER__ORDER_ID:
			setOrder_id((Integer) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__ORDER_DATE:
			setOrder_date((Date) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_ADDRESS:
			setShipping_address((String) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_CITY:
			setShipping_city((String) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_STATE:
			setShipping_state((String) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_COUNTRY:
			setShipping_country((String) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__EXPECTED_SHIPPING_DATE:
			setExpected_shipping_date((Date) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__STATUS:
			setStatus((OrderStatus) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__CLIENT:
			setClient((Client) newValue);
			return;
		case IOMSPackage.PURCHASE_ORDER__ITEMS:
			getItems().clear();
			getItems().addAll((Collection<? extends LineItem>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case IOMSPackage.PURCHASE_ORDER__ORDER_ID:
			setOrder_id(ORDER_ID_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__ORDER_DATE:
			setOrder_date(ORDER_DATE_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_ADDRESS:
			setShipping_address(SHIPPING_ADDRESS_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_CITY:
			setShipping_city(SHIPPING_CITY_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_STATE:
			setShipping_state(SHIPPING_STATE_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_COUNTRY:
			setShipping_country(SHIPPING_COUNTRY_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__EXPECTED_SHIPPING_DATE:
			setExpected_shipping_date(EXPECTED_SHIPPING_DATE_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__STATUS:
			setStatus(STATUS_EDEFAULT);
			return;
		case IOMSPackage.PURCHASE_ORDER__CLIENT:
			setClient((Client) null);
			return;
		case IOMSPackage.PURCHASE_ORDER__ITEMS:
			getItems().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case IOMSPackage.PURCHASE_ORDER__ORDER_ID:
			return order_id != ORDER_ID_EDEFAULT;
		case IOMSPackage.PURCHASE_ORDER__ORDER_DATE:
			return ORDER_DATE_EDEFAULT == null ? order_date != null
					: !ORDER_DATE_EDEFAULT.equals(order_date);
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_ADDRESS:
			return SHIPPING_ADDRESS_EDEFAULT == null ? shipping_address != null
					: !SHIPPING_ADDRESS_EDEFAULT.equals(shipping_address);
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_CITY:
			return SHIPPING_CITY_EDEFAULT == null ? shipping_city != null
					: !SHIPPING_CITY_EDEFAULT.equals(shipping_city);
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_STATE:
			return SHIPPING_STATE_EDEFAULT == null ? shipping_state != null
					: !SHIPPING_STATE_EDEFAULT.equals(shipping_state);
		case IOMSPackage.PURCHASE_ORDER__SHIPPING_COUNTRY:
			return SHIPPING_COUNTRY_EDEFAULT == null ? shipping_country != null
					: !SHIPPING_COUNTRY_EDEFAULT.equals(shipping_country);
		case IOMSPackage.PURCHASE_ORDER__EXPECTED_SHIPPING_DATE:
			return EXPECTED_SHIPPING_DATE_EDEFAULT == null ? expected_shipping_date != null
					: !EXPECTED_SHIPPING_DATE_EDEFAULT
							.equals(expected_shipping_date);
		case IOMSPackage.PURCHASE_ORDER__STATUS:
			return status != STATUS_EDEFAULT;
		case IOMSPackage.PURCHASE_ORDER__CLIENT:
			return client != null;
		case IOMSPackage.PURCHASE_ORDER__ITEMS:
			return items != null && !items.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public double getGrossSales() {
		double sales = 0;
		this.getItems().clear();
		try {
			new LineItemDAOImpl().getOrderItems(this);
		} catch (DataAccessException e) {
		}

		for (LineItem item : getItems()) {
			try {
				new ProductDAOImpl().getProduct(item.getProduct());
			} catch (DataAccessException e) {
			}

			sales += item.getQuantity() * item.getProduct().getPrice();
		}
		return sales;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (order_id: ");
		result.append(order_id);
		result.append(", order_date: ");
		result.append(order_date);
		result.append(", shipping_address: ");
		result.append(shipping_address);
		result.append(", shipping_city: ");
		result.append(shipping_city);
		result.append(", shipping_state: ");
		result.append(shipping_state);
		result.append(", shipping_country: ");
		result.append(shipping_country);
		result.append(", expected_shipping_date: ");
		result.append(expected_shipping_date);
		result.append(", status: ");
		result.append(status);
		result.append(')');
		return result.toString();
	}

	@Override
	public boolean testAttribute(Object target, String name, String value) {
		if (target instanceof PurchaseOrder) {
			if (name.equals("isPending")) {
				return ((PurchaseOrder) target).getStatus().equals(
						OrderStatus.PENDING);
			}
		}
		
		return false;
	}

} // PurchaseOrderImpl
